package cn.hl.hm.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author 大和
 *
 * 采用AOP的方式处理参数问题。
 */
@Component
@Aspect
public class BindingResultAop {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Pointcut("execution(* cn.hl.hm.controller.*.*(..))")
    public void aopMethod(){}

    @Before("aopMethod()")
    public void before() {
        this.printLog("已经记录下操作日志@Before 方法执行前");
    }

    @Around("aopMethod()")
    public void around(ProceedingJoinPoint pjp) throws Throwable{
        this.printLog("已经记录下操作日志@Around 方法执行前");
        Object[] args = pjp.getArgs();
        for (int i = 0; i < args.length; i++) {
			System.out.println(args[i]);
		}
       
        pjp.proceed();
        this.printLog("已经记录下操作日志@Around 方法执行后");
    }

    @After("aopMethod()")
    public void after() {
    	
        this.printLog("已经记录下操作日志@After 方法执行后");
    }

    private void printLog(String str){
    	//log.info(str);
    	//System.out.println(str);
    }
    
    
    @AfterReturning(
            pointcut="execution(* cn.hl.hm.controller.*.*(..))",
            returning="returnValue")
    public void access(Object returnValue) {
       // System.out.println("目标方法的返回结果returnValue = " + returnValue);
    }
    
}
